package com.ihr360.job.core;

import com.ihr360.job.core.scope.context.SimpleStepContext;

/**
 * Listener interface for the processing of an item.  Implementations
 * of this interface will be notified before and after an item is
 * passed to the {@link ItemProcessor} and in the event of any
 * exceptions thrown by the processor.
 *
 * @author Dave Syer
 *
 */
public interface ItemProcessListener<T, S> extends StepListener {

    /**
     * Called before {@link ItemProcessor#process(Object)}.
     *
     * @param item to be processed.
     */
    void beforeProcess(T item,SimpleStepContext simpleStepContext);

    /**
     * Called after {@link ItemProcessor#process(Object)} returns.  If the
     * processor returns null, this method will still be called, with
     * a null result, allowing for notification of 'filtered' items.
     *
     * @param item to be processed
     * @param result of processing
     */
    void afterProcess(T item, S result);

    /**
     * Called if an exception was thrown from {@link ItemProcessor#process(Object)}.
     *
     * @param item attempted to be processed
     * @param e - exception thrown during processing.
     */
    void onProcessError(T item, SimpleStepContext simpleStepContext,Exception e);
}